<!DOCTYPE html> 
<html>
	<meta charset="UTF-8">
	<head>
		<script type="text/javascript">
			var constraints = {audio: true, video: false};
			navigator.getUserMedia = navigator.webkitGetUserMedia;
			
			function successCallBack(stream){
				window.stream = stream;
				console.log(stream);
				if (window.URL) {
				    document.getElementById('localMediaTest').src = window.URL.createObjectURL(stream);  
				}
			    document.getElementById('localMediaTest').play();  
			}

			function failCallBack (error) {
				alert(error.name);
				console.log("navigator.getUserMedia error: ", error.name);
			}

			function test_start(){
				addAudioElement();
				navigator.getUserMedia(constraints, successCallBack, failCallBack);
			}
			
			function test_stop(){
				document.getElementById('localMediaTest').pause();
				removeElement();
			}
			
			function addAudioElement(){
			    var remoteAudio = document.createElement('audio');
				remoteAudio.id = 'localMediaTest';
				remoteAudio.display = 'none';
				document.body.appendChild(remoteAudio);
			}
			
			function removeElement(){
				var element = document.getElementById('localMediaTest');
				element.parentNode.removeChild(element);
			}
		</script>
	</head>

	<body>
		<button onclick="test_start()">开始测试</button>
		<button onclick="test_stop()">结束测试</button>
	</body>
</html>